package com.itheima.Zixi4.ZuoYe.ZuoYe1;

import java.util.*;

public class Zuoye1 {
    public static void main(String[] args) {
        Map<String,Integer> shiyou = new TreeMap<>();
        ShiYou shiyou1 = new ShiYou("张三", 18);
        ShiYou shiyou2 = new ShiYou("李四", 22);
        ShiYou shiyou3 = new ShiYou("王五", 20);
        shiyou.put(shiyou1.getName(), shiyou1.getAge());
        shiyou.put(shiyou2.getName(), shiyou2.getAge());
        shiyou.put(shiyou3.getName(), shiyou3.getAge());
        shiyou.put(shiyou1.getName(), shiyou1.getAge());
        shiyou.put(shiyou2.getName(), shiyou2.getAge());
        shiyou.put(shiyou3.getName(), shiyou3.getAge());
        //遍历Map三种方式：1.键找值
        Set <String> KEYS = shiyou.keySet();
        for (String key : KEYS) {
            Integer value = shiyou.get(key);
            System.out.println(key+"---"+value);
        }
        //2.键值对遍历
        Set <Map.Entry<String, Integer>> entrySet =shiyou.entrySet();
        for (Map.Entry<String, Integer> entry : entrySet) {
            String key = entry.getKey();
            Integer value = entry.getValue();
            System.out.println(key+"---"+value);
        }
        entrySet.forEach(entry->{
            String key = entry.getKey();
            Integer value = entry.getValue();
            System.out.println(key+"---"+value);
        });
        //3.lambda遍历
        shiyou.forEach((key,value)-> {
            System.out.println(key + "---" + value);
        });
    }


}
